﻿@using WD.Web.MVC.Common
@using WD.Db.Contract
@model IEnumerable<WD.Db.Contract.User>

@{
    ViewBag.Title = "WD.Db.Contract.User_Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
    //行序号
    var rowIndex = 0;
}

@section Script
{
    @*<script>
            var id = "User";

            //新增按钮配置信息（弹框）
            var option_add = {
                id: id,
                title: "User信息",
                yesfn: function () {
                    //AJAX加载过渡动画
                    DialogLoading({ id: id }, true);
                    //TODO AJAX保存事件开始

                    $("#User_mainForm").PostForm({
                        vfn: UserCheckField,
                        success: function (data) {
                            msgsuc(data);		//显示成功提示信息
                            SearchTab();		//刷新Index页面 ReloadTab 或者 SearchTab
                            CloseDialog(id);	//关闭窗口
                        },
                        error: function (data) {
                            msgerr(data);
                        },
                        complete: DialogLoading({ id: id }, false)
                    });

                    //TODO AJAX保存事件结束
                },
                yestxt: "保存"
            };


        </script>*@

    <script>
        var id = "User";

        //新增按钮配置信息（弹框）
        var option_add = {
            id: id,
            title: "新增用户",
            yesfn: function () {
                var userId = $("#UserId").val();
                var userName = $("#Name").val();
                if (!userId) {
                    msgerr({ message: "请填写用户帐号！" });
                    return false;
                }
                if (!userName) {
                    msgerr({ message: "请填写用户名！" });
                    return false;
                }
                //AJAX加载过渡动画
                DialogLoading({ id: id }, true);
                //TODO AJAX保存事件开始

                $("#User_mainForm").PostForm({
                    vfn: function () { return true; },
                    success: function (data) {
                        msgsuc(data);
                        //关闭窗口
                        CloseDialog(id);
                        ReloadTab();
                    },
                    error: function (data) {
                        msgerr(data);
                    },
                    //隐藏AJAX加载过渡动画
                    complete: DialogLoading({ id: id }, false)
                });
                //TODO AJAX保存事件结束
            },
            yestxt: "保存"
        };
        //
        var setroleid = "SetRoleShow_id";
        var setroletitle = "分配用户角色";
        var option_setrole = {
            id: setroleid,
            title: setroletitle,
            yesfn: function () {

                //AJAX加载过渡动画
                DialogLoading({ id: setroleid }, true);

                SaveRoleNodes(function () {
                    //隐藏AJAX加载过渡动画
                    DialogLoading({ id: setroleid }, false);
                    //关闭窗口
                    CloseDialog(setroleid);
                });
            },
            yestxt: "分配"
        };

        //
        var setprofit = "setprofit";
        var option_setprofit = {
            id: setprofit,
            title: "设置代理角色",
            yesfn: function () {
                //AJAX加载过渡动画
                DialogLoading({ id: setprofit }, true);


                $("#SetUserProfit_mainForm").PostForm({
                    vfn: SetUserProfitCheckField,
                    success: function (data) {
                        msgsuc(data);
                        //关闭窗口
                        CloseDialog(setprofit);
                        ReloadTab();
                    },
                    error: function (data) {
                        msgerr(data);
                    },
                    //隐藏AJAX加载过渡动画
                    complete: DialogLoading({ id: setprofit }, false)
                });
            },
            yestxt: "确认设置"
        };

        var setPwd = "setPwd";
        var option_setPwd = {
            id: setprofit,
            title: "重置登录密码",
            yesfn: function () {
                //AJAX加载过渡动画
                DialogLoading({ id: setprofit }, true);
                alert("123");

                //$("#SetUserProfit_mainForm").PostForm({
                //    vfn: SetUserProfitCheckField,
                //    success: function (data) {
                //        msgsuc(data);
                //        //关闭窗口
                //        CloseDialog(setprofit);
                //        ReloadTab();
                //    },
                //    error: function (data) {
                //        msgerr(data);
                //    },
                //    //隐藏AJAX加载过渡动画
                //    complete: DialogLoading({ id: setprofit }, false)
                //});
            },
            yestxt: "确认设置"
        };


        //账户money按钮配置信息（弹框）
        var option_setmoney = {
            id: id,
            title: "账户充值",
            yesfn: function () {
                //AJAX加载过渡动画
                DialogLoading({ id: id }, true);
                //TODO AJAX保存事件开始

                $("#User_mainFormMoney").PostForm({
                    vfn: UserCheckField,
                    success: function (data) {
                        msgsuc(data);		//显示成功提示信息
                        SearchTab();		//刷新Index页面 ReloadTab 或者 SearchTab
                        CloseDialog(id);	//关闭窗口
                    },
                    error: function (data) {
                        msgerr(data);
                    },
                    complete: DialogLoading({ id: id }, false)
                });

                //TODO AJAX保存事件结束
            },
            yestxt: "保存"
        };
    </script>
}

@section ToolbarArea{
    @*<a href="@Url.Action("Create")" target="edit" data-option='option_add' class="btn pull-left">
        <i class="fa fa-plus"></i>新增
    </a>*@
}


@section SearchArea{

}

@section MainTable{
    <table class="table">
        <thead>
            <tr>
                <th class="text-left"><span>序号</span></th>
                <th><a href="#" role="sort" data-field="Name"><span>用户名</span></a></th>
                <th><a href="#" role="sort" data-field="UserId"><span>登录名</span></a></th>
                <th><a href="#" role="sort" data-field="Type"><span>用户类型</span></a></th>
                <th><a href="#" role="sort" data-field="InvBy"><span>上级用户</span></a></th>
                <th><a href="#" role="sort" data-field="Pro"><span>所属区域</span></a></th>
                <th><a href="#" role="sort" data-field="CreateTime"><span>注册时间</span></a></th>
                <th><a href="#" role="sort" data-field="IsAgent"><span>是否代理</span></a></th>
                <th><a href="#"><span>代理详情</span></a></th>
                <th class="text-right"><span>操作</span></th>


            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                rowIndex++;
                <tr>
                    <td>
                        @item.ID
                    </td>

                    <td>
                        @Html.DisplayFor(modelItem => item.Name)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.UserId)
                    </td>
                    <td>
                        @try
                        {
                            @CommonCache.CodeDataByCache[item.Type].CodeName
                        }
                        catch (Exception)
                        {
                        }

                    </td>
                    <td>
                        @try
                        {
                            @item.UserParent.Name;
                        }
                        catch (Exception)
                        {
                            <span>无</span>
                        }
                    </td>
                    <td>
                        @{
                var strPro = item.Pro + "-" + item.City + "-" + item.Dis;
                <span>@strPro</span>
                        }
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.CreateTime)
                    </td>
                    <td>
                        @{
                try
                {
                    if (item.IsAgent > 0)
                    {
                        @*@CommonCache.CodeDataByCache[item.AgentManager.AgentType].CodeName;*@
                    }
                    else
                    {
                        <span>否</span>
                    }
                }
                catch (Exception)
                {

                }
                        }
                    </td>
                    <td>
                        @{
                try
                {
                    if (item.IsAgent > 0)
                    {
                        @*var agentManager = item.AgentManager;

                            var proaddress = agentManager.Pro + " ";
                            if (agentManager.AgentType == CommonCode.区域角色_市级代理)
                            {
                                proaddress += agentManager.City;
                            }
                            else if (agentManager.AgentType == CommonCode.区域角色_区级代理)
                            {
                                proaddress += agentManager.City + " " + agentManager.Dis;
                            }
                            @proaddress*@

                    }
                    else
                    {
                        <span>否</span>
                    }
                }
                catch (Exception)
                {

                }
                        }
                    </td>

                    <td class="text-right">
                        @if (ViewBag.userId == "caiwu")
                        {

                            <a href="@Url.Action("setUserMoney", new { id = item.ID })" class="table-link" target="edit" data-option='option_setmoney'>
                                <span class="fa-stack">
                                    <i class="fa fa-square fa-stack-2x"></i>
                                    <i class="fa fa-cog fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>

                        }
                        @*<a href="@Url.Action("Edit", new { id = item.ID })" title="修改该用户信息" class="table-link" target="edit" data-option='option_add'>
                            <span class="fa-stack">
                                <i class="fa fa-square fa-stack-2x"></i>
                                <i class="fa fa-pencil fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>*@
                        <a href="@Url.Action("Deleted", new { ids = item.ID })" title="删除该用户" class="table-link danger" target="ajax" data-reload="true">
                            <span class="fa-stack">
                                <i class="fa fa-square fa-stack-2x"></i>
                                <i class="fa fa-trash-o fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                        @*<a href="@Url.Action("SetUserProfit", new { id = item.ID })" title="设置代理" class="table-link danger" target="edit" data-option='option_setprofit'>
                            <span class="fa-stack">
                                <i class="fa fa-square fa-stack-2x"></i>
                                <i class="fa fa-male fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>*@
                    </td>
                </tr>
            }
        </tbody>
    </table>
}


